package cn.ycxy.lbl.member.controller;


import cn.ycxy.lbl.common.restful.R;
import cn.ycxy.lbl.member.service.IUserService;
import cn.ycxy.lbl.member.utils.LoginUtils;
import cn.ycxy.lbl.pojo.member.dto.UserLoginDTO;
import cn.ycxy.lbl.pojo.member.vo.LoginSuccessVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@Api(tags = "前台管理用户认证")
@RestController
@RequestMapping("/sso")
public class UserSSOController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "前台单点登录认证登录")
    @PostMapping("/weixin/login")
    public R<LoginSuccessVO> login(@Valid @RequestBody UserLoginDTO userLoginDTO, HttpServletRequest request){
        userLoginDTO.setIp(LoginUtils.getIpAddress(request));
        //https://api.weixin.qq.com/sns/jscode2session?appid=wx28f98ebaab321924&secret=ad00f884dc132a0cae8e6a0b0ddefc7f&js_code=041YfVkl2DewVa4Onynl2OmLtp1YfVkE
        LoginSuccessVO loginSuccessVO = userService.doLogin(userLoginDTO);
        return R.ok(loginSuccessVO);
    }


}
